#include <QCoreApplication>
#include <QFile>
#include <QObject>
#include <QDebug>
#include <QString>

int main(int argc, char *argv[])
{
    if (argc != 3){
        qDebug() << "Usage: copy <src_file> <dst_file>";
        return 0;
    }

    QFile srcFile(argv[1]), destFile(argv[2]);

    if (!srcFile.open(QIODevice::ReadOnly | QIODevice::Text)){
        qDebug() << QObject::tr("Open file %1 error: %2")
                    .arg(argv[1]).arg(srcFile.errorString());
        return 0;
    }

    if (!destFile.open(QIODevice::WriteOnly | QIODevice::Text)){
        qDebug() << QObject::tr("Open file %1 error: %2")
                    .arg(argv[2]).arg(destFile.errorString());
        return 0;
    }

    QByteArray buffer = srcFile.readAll();
    if (!buffer.isEmpty()){
        destFile.write(buffer);
        qDebug() << QObject::tr("Write %1 bytes.").arg(buffer.size());
    }

    return 0;
}


